<template>
  <el-form label-position="top"
           :model="data"
           ref="form"
           style="margin: 10px; width: auto"
  >
    <el-form-item prop="qtType" label="* 字典类型">
      <el-input v-model="data.dictType"></el-input>
    </el-form-item>
    <el-form-item prop="qtType" label="* 字典值">
      <el-input v-model="data.dictName"></el-input>
    </el-form-item>

    <el-form-item>
      <div class="w_full flex-row center-center" style="margin-top: 32px;">
        <el-button size="large" type="primary" @click="click_ok">创建</el-button>
      </div>
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import {useUserStore} from "@/store/user";
import {onMounted, reactive, ref} from "vue";
import {FormInstance} from "element-plus";
import msg from '@/components/msg'
import {api_addDict} from "@/request/apis/assistantApi";
import {DictQueryDto} from "@/type/dto/DictQueryDto";
import {DICT_TYPE_LEVEL, DICT_TYPE_POSITION, DICT_TYPE_TITLE} from "@/constants/Constants_DictType";

const userStore = useUserStore()

const props = defineProps({});
const emit = defineEmits(["close"])
const form = ref<FormInstance>();

const data = reactive({
      dictName: '',
      dictType: '',
    }
);

const click_ok = async () => {
  if (!data.dictName) {
    await msg.info('请输入字典值');
    return;
  }
  if (!data.dictType) {
    await msg.info('请输入字典类型');
    return;
  }

  const dictQueryDto: DictQueryDto = {dictName: data.dictName, dictType: data.dictType}

  const r = await api_addDict(dictQueryDto);
  if (!r) {
    await msg.info('创建字典异常', '提示', {
      confirmButtonText: '确定',

    });
    return;
  }
  if (r.code != 0) {
    await msg.info(`创建字典异常  ${r.code} msg：${r.msg}`, '提示', {
      confirmButtonText: '确定'
    });
    return;
  }
  //这里调用创建接口
  emit("close", true);
}
</script>

<style scoped>

</style>